#购买零钱理财和剩余钱的逻辑操作
import time


from selenium.webdriver.common.by import By

class Loginzhong:
#购买零钱理财逻辑操作
    def buy(self,driver, pwd):
        ele4 = driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[2]/a")
        ele4.click()
        time.sleep(1)
        ele5 = driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[2]/ul/li[1]/a")
        ele5.click()
        time.sleep(1)
        ele6 = driver.find_element(By.XPATH,
                                   "/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button")
        ele6.click()
        time.sleep(1)
        ele6 = driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password")
        ele6.send_keys(int(pwd))
        time.sleep(1)
        ele7 = driver.find_element(By.XPATH, "//*[@id='layui-layer1']/div[3]/a[1]")
        ele7.click()
        time.sleep(1)
 # 获取买入成功文本
    def getSuccssBuy(self, driver):
        result = driver.find_element(By.XPATH,
                                     "/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[3]/div/div").text
        time.sleep(5)
        # 点击确定
        ele8 = driver.find_element(By.XPATH, "/html/body/div[3]/div[2]/div/div/div/div/div/div/div/div[4]/button")
        ele8.click()
        time.sleep(1)
        return  result
#获取最初余额
    def getMoney(self,driver):
        # 点击个人中心
        ele12 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[4]/a")
        ele12.click()
        time.sleep(1)
        # 点击银行卡管理
        ele13 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[3]/a")
        ele13.click()
        time.sleep(1)
        # 获取购买前账户余额
        result2 = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]").text
        result2 = float(result2[5:-1])
        expect2  = result2
        return result2
# 获取现在余额
    def getBalance(self, driver):
        # 点击个人中心
        ele12 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[4]/a")
        ele12.click()
        time.sleep(1)
        # 点击银行卡管理
        ele13 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[3]/a")
        ele13.click()
        time.sleep(1)
        result3 = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div[2]/div/div/div[2]/h4[2]").text
        result3 = float(result3[5:-1])
        return result3
#购买基金理财逻辑操作
    def  buy2(self,driver,pwd):
        # 点击个人理财
        ele4 = driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[2]/a")
        ele4.click()
        time.sleep(1)
        # 点击期限理财
        ele5 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[2]/a")
        ele5.click()
        time.sleep(1)
        # 点击支付宝期限理财投资
        ele6 = driver.find_element(By.XPATH,
                                   "/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button")
        ele6.click()
        time.sleep(1)
        # 输入密码
        ele6 = driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password")
        ele6.send_keys(int(pwd))
        time.sleep(1)
        # 点击确定
        ele7 = driver.find_element(By.XPATH, "//*[@id='layui-layer1']/div[3]/a[1]")
        ele7.click()
        time.sleep(1)
#购买基金理财逻辑操作
    def buy3(self,driver,pwd):
        # 点击个人理财
        ele4 = driver.find_element(By.XPATH, "//*[@id='leftbaraside']/div[2]/nav/ul/li[2]/a")
        ele4.click()
        time.sleep(1)
        # 点击基金理财
        ele5 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[2]/ul/li[3]/a")
        ele5.click()
        time.sleep(1)
        # 点击广发多元新兴股票-投资
        ele6 = driver.find_element(By.XPATH,
                                   "/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button")
        ele6.click()
        time.sleep(1)
        # 输入密码
        ele6 = driver.find_element(By.CSS_SELECTOR, ".layui-layer-content > #password")
        ele6.send_keys(int(pwd))
        time.sleep(1)
        # 点击确定
        ele7 = driver.find_element(By.XPATH, "//*[@id='layui-layer1']/div[3]/a[1]")
        ele7.click()
        time.sleep(1)
#金融贷款逻辑操作
    def buy4(self,driver,money,day):
        # 点击金融工具
        ele4 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[3]/a")
        ele4.click()
        time.sleep(1)
        # 点击安全网贷
        ele5 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a")
        ele5.click()
        time.sleep(1)
        # 输入借款金额
        ele6 = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input")
        ele6.send_keys(int(money))
        time.sleep(3)
        # 输入借款期限
        ele7 = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input")
        ele7.send_keys(int(day))
        time.sleep(1)
        # 点击申请
        ele8 = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button")
        ele8.click()
        time.sleep(2)
        # 点击确定
        ele9 = driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]")
        ele9.click()
        time.sleep(0.3)
#获取申请文本
    def  getSuccssTxt(self,driver):
        result = driver.find_element(By.XPATH, "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[3]/div/div").text
        return result
#重新登录
    def alogin(self,driver):
        # 点击头像
        ele21 = driver.find_element(By.XPATH, '/html/body/div/div/header/nav/div/ul/li[1]/a/img')
        ele21.click()
        time.sleep(1)
        # 点击退出登录
        ele22 = driver.find_element(By.XPATH, '/html/body/div/div/header/nav/div/ul/li[1]/ul/li[4]/a')
        ele22.click()
        time.sleep(1)
#管理员同意贷款的逻辑操作
    def agree(self,driver):
        ele13 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[5]/a")
        ele13.click()
        time.sleep(1)
        # 点击网贷审核
        ele14 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[5]/ul/li[1]/a")
        ele14.click()
        time.sleep(1)
        # 点击审核通过
        ele15 = driver.find_element(By.XPATH,
                                    "/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr/td[7]/button[1]")
        ele15.click()
        time.sleep(1)
        # 点击确定
        ele16 = driver.find_element(By.XPATH,
                                    "/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]")
        ele16.click()
        time.sleep(1)
#管理员退出
    def aalogin(self,driver):
        # 点击头像
        ele21 = driver.find_element(By.XPATH, '/html/body/div/div/header/nav/div/ul/li[1]/a/img')
        ele21.click()
        time.sleep(1)
        # 点击退出登录
        ele22 = driver.find_element(By.XPATH, '/html/body/div/div/header/nav/div/ul/li[1]/ul/li/a')
        ele22.click()
        time.sleep(1)
#获取期限不合格文本
    def getTxt(self,driver):

        result = driver.find_element(By.XPATH,
                                         "/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/span").text
        return result
# 申请贷款2
    def  buy5(self,driver,money,day):
        # 点击金融工具
        ele4 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[3]/a")
        ele4.click()
        time.sleep(1)
        # 点击安全网贷
        ele5 = driver.find_element(By.XPATH, "/html/body/div/div/aside/div[2]/nav/ul/li[3]/ul/li[2]/a")
        ele5.click()
        time.sleep(1)
        # 输入借款金额
        ele6 = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[1]/input")
        ele6.send_keys(int(money))
        time.sleep(3)
        # 输入借款期限
        ele7 = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[3]/input")
        ele7.send_keys(int(day))
        time.sleep(1)
        # 点击申请
        ele8 = driver.find_element(By.XPATH, "/html/body/div/div/main/div/div/div/div/div[2]/div/form/div[4]/button")
        ele8.click()
        time.sleep(2)









